#include "widget.h"
#include "ui_widget.h"
#include <QResizeEvent>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //先获取窗口大小,再设置标签大小和窗口一样
    QRect windownRect=this->geometry();
    ui->label->setGeometry(0,0,windownRect.width(),windownRect.height());

    QPixmap pixmap(":/1.jpeg");
    ui->label->setPixmap(pixmap);
    //设置图片自动拉伸铺满整个窗口
    ui->label->setScaledContents(true);
}

Widget::~Widget()
{
    delete ui;
}
//event触发该信号时窗口的大小
void Widget::resizeEvent(QResizeEvent *event)
{
    qDebug()<<event->size();
    ui->label->setGeometry(0,0,event->size().width(),event->size().height());
}

